<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../../css/mui.min.css">
		<script src="../../js/mui.min.js"></script>
		<script type="text/javascript" src="../../js/global.js" ></script>
	</head>
	<body>
		
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">灾害列表</h1>
		</header>
		<div class="mui-content">
			<ul class="mui-table-view mui-table-view-chevron" id="listBox"></ul>
		</div>
		<script>
			mui.init({
				gestureConfig:{
					tap:true,
					doubletap:true
				}
			});
			var save=[
				{
					src:'../../images/warn/SAVE.png',
					title:'无凝冻预警'
				},{
					src:'../../images/warn/SAVE.png',
					title:'无大雾预警'
				},{
					src:'../../images/warn/SAVE.png',
					title:'无暴雨预警'
				}
				
			];
			function returnDom(obj,mode){
				var src=save[mode-1].src;
				var title=save[mode-1].title;
				var desc=obj.time;
				var val="";
				if(mode==1){
					val=obj.freez;
				}else if(mode==2){
					val=obj.vis;
				}else if(mode==3){
					val=obj.rain;
				}
				for(var i=0;i<DIS_AREA[mode-1].length;i++){
					if(val>DIS_AREA[mode-1][i].min && val<=DIS_AREA[mode-1][i].max){
						src='../../'+DIS_AREA[mode-1][i].src;
						title=DIS_AREA[mode-1][i].text;
						desc=obj.time;
						break;
					}
				}
				var res='<li class="mui-table-view-cell mui-media">'+
							'<a class="mui-navigate">'+
								'<img class="mui-media-object mui-pull-left" src="'+src+'">'+
								'<div class="mui-media-body">'+title+
									'<p class="mui-ellipsis">'+desc+'</p>'+
									'<input type="hidden" value="'+val+'">'
								'</div>'+
							'</a>'+
						'</li>';
				return res;
			}
			function reloadData(lng,lat,mode){
				
				mui.ajax(
					FORCAST_DATA,
					{
						data:{
							lng:lng,
							lat:lat,
							level:3
						},
						dataType:'json',
						type:'get',
						success:function(data){
							var mdata=data.obj.data;
							var listBox=document.getElementById("listBox");
							var donText='';
							for(var i=0;i<mdata.length;i++){
								donText+=returnDom(mdata[i],mode);
							}
							listBox.innerHTML=donText;
							mui("#listBox").on("doubletap","li",function(){
								var input=this.children[0].children[1].children[1];
								mui.toast(input.getAttribute("value"));
							})
						},
						error:function(xhr,type,error){
							mui.toast("服务器断开，请联系管理员。code："+type)
						}
					}
				)
			}
			
			//初始进入加载
			mui.plusReady(function(){
				var self=plus.webview.currentWebview();
				var lng=self.lng;
				var lat=self.lat;
				var mMode=self.mMode;
				reloadData(lng,lat,mMode);
			});
			
		</script>
	</body>
</html>
